package xyz.flowlight.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import xyz.flowlight.domain.entity.Cart;
import xyz.flowlight.domain.entity.Product;
import xyz.flowlight.domain.response.ResponseResult;
import xyz.flowlight.service.ProductService;

import java.math.BigDecimal;
import java.util.List;

@Tag(name = "产品相关接口")
@RestController
@RequestMapping("/product")
public class ProductController {
    @Resource
    private ProductService productService;

    @GetMapping("/search")
    public ResponseResult<List<Product>> search(@RequestParam("keyword") String keyword) {
        return productService.searchProducts(keyword);
    }

    @PostMapping("/cart/add")
    public ResponseResult<Void> addToCart(@RequestParam Integer productId,
                                        @RequestParam(defaultValue = "1") Integer quantity,
                                          @RequestHeader("userId") Integer userId) {
        return productService.addToCart(userId, productId, quantity);
    }
    @GetMapping("/list")
    public ResponseResult<List<Product>> getAllProducts() {
        List<Product> products = productService.getAllProducts();
        return ResponseResult.success(products);
    }

}
